
/**
 * Class containing the Gene strategy.
 * @author	081028AW
 */
// The chromosome is hard coded so professor Wu can run this strategy without any
// additional files. The Chromosome was evolved using the params below.
//
//Experiment ID                :prisoner
//Problem Type                 :PD
//Data Input File Name         :NA
//Number of Runs               :100
//Generations per Run          :100
//Population Size              :100
//Selection Method (1)         :2
//Fitness Scaling Type (2)     :0
//Crossover Type (3)           :3
//Crossover Rate (4)           :1.0
//Mutation Type (5)            :1
//Mutation Rate (6)            :0.001 
//Random Number Seed           :75982
//Number of Genes/Points (7)   :1
//Size of Genes (8)            :70
//Number of individuals in Game:5
//Type of Strategy(9)          :3//
// It is the best overall
//#B      best Over All chromo 
//#R: 52  G: 68  Fitness: 525.0
//#0000000001000010100000001101010000000110000000010000000000001111000001
//        #   RawFitness: -2143288392          525



public class StrategyHRTKnown extends Strategy
   {
  /**
   * Encoding for Gene strategy.
   */

   int numDefects;
   static int LengthExpected = 70;
   String previousMoves;
   String gene;
   boolean firstMove = true;

  // 0 = defect, 1 = cooperate

   public StrategyHRTKnown()
      {
      name = "Gene";
      gene = "0000000001000010100000001101010000000110000000010000000000001111000001";
      opponentLastMove = 1;
      numDefects = 0;
      if (gene.length() != LengthExpected)
      {
    	  //error rcm
      }
      }  /* StrategyGene */

   public int nextMove()
      {
	   if (firstMove)
	   {
		   firstMove = false;
		   previousMoves = gene.substring(64);
	   }
	   else
	   {
		   previousMoves += opponentLastMove;
	   }
	
	   int previousMovesIndex = Integer.parseInt(previousMoves, 2);
	  
	   String move = gene.substring(previousMovesIndex, previousMovesIndex+1);
	  
	   int nextMove = Integer.parseInt(move);
	   
	   String previous2Moves = previousMoves.substring(2);
	   previousMoves = previous2Moves + nextMove;
	  
	   return nextMove;
      }  /* nextMove */

   }  /* class StrategyHRTKnown */
